/*
 * @(#)AesSessionUserFactory.java   1.0  2018年8月31日
 *
 * Copyright (c)	2014-2020. All Rights Reserved.	GuangZhou hhmk Technology Company LTD.
 */
package com.swift.dts.service.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.swift.core.session.AbstractSession;
import com.swift.core.session.SessionCrypt;
import com.swift.util.security.AESUtil;
import com.swift.util.type.JsonUtil;
import com.swift.util.type.TypeUtil;

/**
 * 添加说明
 *
 * @author zhengjiajin
 * @version 1.0 2018年8月31日
 */
@Component
public class AesSessionUserFactory implements SessionCrypt {
    private static final Logger log = LoggerFactory.getLogger(AesSessionUserFactory.class);
    // AES加密密钥
    public static final String AESKEY = "abcdefgabcdefg12";

    @Override
    public String encrypt(AbstractSession sessionUser) {
        if (sessionUser == null) {
            return null;
        }
        return AESUtil.encrypt(JsonUtil.toJson(sessionUser), AESKEY);
    }

    @Override
    public AbstractSession decrypt(String sessionUser) {
        if (TypeUtil.isNull(sessionUser)) {
            return null;
        }
        log.info("登录用户信息:"+sessionUser);
        return JsonUtil.toObj(AESUtil.decrypt(sessionUser, AESKEY), AbstractSession.class);
    }
    
    public static void main(String[] args) {
        String value = "541BB4E8D91F2A48832824527E18B03DD691754445365C4F5571C48E6F430D7EADE4783A04981F7DBB1CDC902CE0C3C6F03E85552FBDDA1F258AED8C98EB684661074C810C176242454B384CF71A9416C5AA77A1D765236E2292A153B0E96F5CF65273814BFE463EDD12889163867A9622E6A12CF6DCE79DE705B5584308035316AEE7D060C3C85DF14DC62087E34A5A1C9967A9EDB88E7839C1C872F5C58A73DEE80BF49710268B224A2F241A8E3476DDC7744D8E022A9B8DAE8F4AF59E2BA30056B759C9DB07EB0DB7852F8578EDA3F2477D4C765F5738B04A9F83BB9337C929E4372C62572DEF6B5601A09A4F85BA6F5CB8FCEAB74373217DECD69080263D104BD38661D9AAF24F922B0F6618C3DF289529EB19037561A6A974548297ACC8";
        System.out.println(AESUtil.decrypt(value, AESKEY));
    }
}
